# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/11 20:52
from PyQt5.Qt import *

class Slider(QSlider):
	def __init__(self,parent=None,*args,**kwargs):
		super().__init__(parent,*args,**kwargs)
		self.setup_ui()

	def setup_ui(self):
		self.label = QLabel(self)
		# self.label.setText('0')
		self.setTickPosition(QSlider.TicksBothSides)

	def mouseMoveEvent(self, evt):
		# QMouseEvent
		super().mouseMoveEvent(evt)
		x=(self.width()-self.label.width())/2
		y=(1-self.value()/(self.maximum()-self.minimum()))*(self.height()-self.label.height())
		# print(x,y)
		self.label.show()
		self.label.setStyleSheet('color:red')
		self.label.move(int(x),int(y))

		self.label.setText(str(self.value()))
		self.label.adjustSize()

	def mouseReleaseEvent(self, evt):
		super().mouseReleaseEvent(evt)
		self.label.hide()




class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QSlider综合案例学习')
		self.resize(500, 500)
		self.setup_ui()

	def setup_ui(self):
		# 0 创建两个控件
		slider = Slider(self)
		slider.move(200,200)
		slider.resize(30,200)





if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())